from core.basehandler import BaseHandler
from core.room import Room
from core.action import Action
from core.support import set_cutscene
#from core.support import get_game

class Bar(Room):
    def __init__(self, room_id):
        Room.__init__(self, room_id)    # do basic initialization for every room
        
        # add inventory items
        #self.add_item(BrokenMeter())
        
        # build list of actions
        self.add_action(OrderDrink)
        self.add_action(WalkAwayFromBar)
        #self.game = get_game() 
        #self.player = self.game.get_player()
        #self.player.pop_item('Pointer()')
        
    # return description of room.
    def get_description(self):
        return "You are standing at a crowded bar and trying to order a drink."
    
    # return image of room
    def get_image(self):
        return 'bar_image.jpg'


class BarHandler(BaseHandler):
    
    # return class to use to create a new instance of this room
    def get_room_class(self):
        return Bar
    
    def get_template(self):
        player = self.game.get_player()
        if player.beers_count == 5:
            return 'room2.html'
        else:
            return 'room.html'
# define actions for this room

class OrderDrink(Action):
    def __init__(self):
        Action.__init__(self, "OrderDrink")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Order Drink"
    
    # return id of room to enter when action is complete
    def get_destination(self):
        return 'bar'
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "post"
    
    def do_action(self,game,room,request):
        p = game.get_player()
        if p.beers_count < 5:
            p.beers_count += 1
            p.confidence += 1
            set_cutscene("You drink a beer and feel more confident. Confidence level is "+str(p.confidence))
            if p.beers_count == 4:
                set_cutscene("You drink a beer and feel more confident. Confidence level is "+str(p.confidence)+". You already feel drunk. One more beer and the world will become blurry")
            if p.beers_count == 5:
                set_cutscene("You drink a beer and feel more confident. Confidence level is "+str(p.confidence)+". Congrats, now you are really drunk and can't see things clearly.")
        else:
            set_cutscene("You can't drink anymore!")
        return
    

class WalkAwayFromBar(Action):
    def __init__(self):
        Action.__init__(self, "WalkAwayFromBar")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Walk Away From Bar"
    
    # return id of room to enter when action is complete
    def get_destination(self):
        return 'cornwalls'
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"